package com.tan00xu.config;


import com.tan00xu.handler.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Resource
    @Autowired
    private LoginInterceptor loginInterceptor;
//    @Bean
//    public LoginInterceptor getLoginInterceptor() {
//        return new LoginInterceptor();
//    }
    /**
     * 跨域配置
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins(
                        "*",
                        "http://localhost:8080",
                        "http://192.168.106.1:8080/",
                        "http://192.168.147.1:8080/",
                        "http://192.168.137.1:8080/",
                        //外部ip
                        "http://192.168.189.1"
                        )
                .allowedMethods("*");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns(
                        "/test",
                        "/comments/createComment",
                        "/article/publishArticle"
                );

    }


}
